package de.clapp.client.menue.filter;

import java.util.Arrays;

import javax.swing.RowFilter;
import javax.swing.table.TableRowSorter;

import de.clapp.client.menue.MenueTableModel;

public class MenueCardFilterModel
{
    private RowFilter<MenueTableModel, Object>[] filterArray;

    private TableRowSorter<MenueTableModel> sorter;

    @SuppressWarnings("unchecked")
    public MenueCardFilterModel(int columns, TableRowSorter<MenueTableModel> sorter)
    {
        this.filterArray = new RowFilter[columns];
        this.sorter = sorter;

        for (int i = 0; i < columns; i++)
        {
            this.filterArray[i] = RowFilter.regexFilter("", i);
        }
    }

    public void addFilter(RowFilter<MenueTableModel, Object> filter, int column)
    {
        this.filterArray[column] = filter;
        RowFilter<MenueTableModel, Object> allFilter = RowFilter.andFilter(Arrays.asList(filterArray));
        this.sorter.setRowFilter(allFilter);
    }
}
